<?php
/**
 * Joomla! 1.5 component JoomGPSTracks
 *
 * @version $Id: install.joomgpstracks.php 2009-06-24 15:40:19 svn $
 * @author Michael Pfister
 * @package joomGPStracks
 * @subpackage backend
 * @license GNU/GPL
 * @filesource
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.filesystem.folder' );

?>
<script type="text/javascript">
        window.addEvent('domready', function(){
                $('start').addEvent('click', function(e) {
                        e = new Event(e).stop();

                        var url = "index.php?option=com_joomgpstracks&task=installclean&controller=config";

                        /**
                         * The simple way for an Ajax request, use onRequest/onComplete/onFailure
                         * to do add your own Ajax depended code.
                         */
                        new Ajax(url, {
                                method: 'get',
                                onComplete: document.getElementById('result').innerHTML = 'Database tables installed!'
                        }).request();
                });

        });

        window.addEvent('domready', function(){
                $('update').addEvent('click', function(e) {
                        e = new Event(e).stop();

                        var url = "index.php?option=com_joomgpstracks&task=installupdate&controller=config";

                        /**
                         * The simple way for an Ajax request, use onRequest/onComplete/onFailure
                         * to do add your own Ajax depended code.
                         */
                        new Ajax(url, {
                                method: 'get',
                                onComplete: document.getElementById('result').innerHTML = 'Database tables updated!'
                        }).request();
                });

        });
</script>
<table class="adminlist">
    <tr>
        <td rowspan="2" valign="top"><img src="../components/com_joomgpstracks/assets/images/gps-logo.jpg" width="250" height="250" alt="gps-logo"/>
        </td>
        <td>Welcome to joomGPStracks! Released under the terms and conditions of the <a href="http://www.gnu.org/licenses/gpl-2.0.html" target="_blank">GNU General Public License</a>.</td>
    </tr>
    <tr>
      <td>Now we create the neccesary folders. If an error occur, create the folders manuel, please!</td>
    </tr>
</table>
<?php
if(JFolder::create(JPATH_SITE.'/images/joomgpstracks', 0777)) {
    echo "<font color='green'>FINISHED:</font> Directory /images/joomgpstracks created.<br />";
} else {
    echo "<font color='red'>ERROR:</font> Directory /images/joomgpstracks NOT created.<br />";
}

if(JFolder::create(JPATH_SITE.'/images/joomgpstracks/cats', 0777)) {
    echo "<font color='green'>FINISHED:</font> Directory /images/joomgpstracks/cats created.<br />";
} else {
    echo "<font color='red'>ERROR:</font> Directory /images/joomgpstracks/cats NOT created.<br />";
}
?>
<table class="adminlist" width="400px" align="center">
    <thead>
        <tr>
            <th>Database Installation</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="2"><b>We have to install all necessary database tables. Please click on the button.</b></td>
        </tr>
        <tr>
            <td><a href="#" id="start"><input type="button" value="new install" name="button" class="button"  /></a></td>
            <td><a href="#" id="update"><input type="button" value="update" name="button" class="button"  /></a></td>
        </tr>
        <tr>
            <td colspan="2"><div id="result"></div></td>
        </tr>
    </tbody>
</table>
<?php

?>